home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / overview / dtscpluslibrary / sources / appleevent.cp next >
Encoding:
Text File  |  2000-09-28  |  4.6 KB  |  181 lines

  1. /*
  2.     File:        AppleEvent.cp
  3.  
  4.     Contains:    TAppleEvent is an Apple Event class that will send and receive Apple Events.
  5.                   AppleEvent.cp contains the member functions for the TAppleEvent class.
  6.  
  7.     Written by: Kent Sandvik    
  8.  
  9.     Copyright:    Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved.
  10.  
  11.                 You may incorporate this Apple sample source code into your program(s) without
  12.                 restriction. This Apple sample source code has been provided "AS IS" and the
  13.                 responsibility for its operation is yours. You are not permitted to redistribute
  14.                 this Apple sample source code as "Apple sample source code" after having made
  15.                 changes. If you're going to re-distribute the source, we require that you make
  16.                 it clear in the source that the code was descended from Apple sample source
  17.                 code, but that you've made changes.
  18.  
  19.     Change History (most recent first):
  20.                 8/18/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  21.                 
  22.  
  23. */
  24. // INCLUDE FILES
  25. #ifndef _APPLEEVENT_
  26. #include "AppleEvent.h"
  27. #endif
  28.  
  29. //    GLOBALS
  30. const ProcessSerialNumber kSelf = {
  31.                                    0, kCurrentProcess};
  32.  
  33.  
  34. // _________________________________________________________________________________________________________ //
  35. // TAppleEvent class member function implementations
  36. //    CONSTRUCTORS & DESTRUCTORS
  37. #pragma segment AppleEvent
  38. TAppleEvent::TAppleEvent()
  39. // Create a kCurrentProcess address Apple Event.
  40. {
  41.     this->Initialize();
  42.     fError = ::AECreateDesc(typeProcessSerialNumber, (Ptr) & kSelf, sizeof(ProcessSerialNumber), &fTarget);
  43.     VASSERT(fError == noErr, ("Problems with AECreateDesc = %d", fError));
  44. }
  45.  
  46.  
  47. #pragma segment AppleEvent
  48. TAppleEvent::TAppleEvent(OSType signature)
  49. // Create an AE based on the signature type.
  50. {
  51.     this->Initialize();
  52.     fSignature = signature;
  53.  
  54.     // Create an AEDescriptor from the signature.
  55.     fError = ::AECreateDesc(typeApplSignature, (Ptr) & fSignature, sizeof(fSignature), &fTarget);
  56.     VASSERT(fError == noErr, ("Problems with AECreateDesc = %d", fError));
  57. }
  58.  
  59.  
  60. #pragma segment AppleEvent
  61. TAppleEvent::~TAppleEvent()
  62. {
  63.     ::AEDisposeDesc(&fAE);                        // dispose our AE handle
  64. }
  65.  
  66.  
  67. #pragma segment AppleEvent
  68. void TAppleEvent::Initialize()
  69. // Initialize fields to known values.
  70. {
  71.     fPriority = kAENormalPriority;                // normal level of priority
  72.     fTimeout = kNoTimeOut;                        // no waiting, just continue
  73.     fSendMode = kAENoReply;                        // default we are not expecting replies
  74.     fAE.dataHandle = NULL;                        // clear the message part
  75. }
  76.  
  77.  
  78. //    MAIN INTERFACES
  79. #pragma segment AppleEvent
  80. OSErr TAppleEvent::Define(AEEventClass theClass,
  81.                           AEEventID ID)
  82. // Define the AE based on the AE class and ID.
  83. {
  84.     fError = ::AECreateAppleEvent(theClass, ID, &fTarget, kAutoGenerateReturnID, kAnyTransactionID, &fAE);
  85.     VASSERT(fError == noErr, ("Problems with AECreateAppleEvent = %d", fError));
  86.  
  87.     return fError;
  88. }
  89.  
  90.  
  91. #pragma segment AppleEvent
  92. OSErr TAppleEvent::Send()
  93. // Blast off the Apple Event.
  94. {
  95.     fError = ::AESend(&fAE, &fReply, fSendMode, fPriority, fTimeout, nil, nil);
  96.     VASSERT(fError == noErr, ("Problems with AESend = %d", fError));
  97.  
  98.     return fError;
  99. }
  100.  
  101.  
  102. #pragma segment AppleEvent
  103. OSErr TAppleEvent::Send(AEEventClass theClass,
  104.                         AEEventID ID)
  105. // Blast off the AE with the specs
  106. {
  107.     this->Define(theClass, ID);                    // define the AE
  108.     fError = ::AESend(&fAE, &fReply, fSendMode, fPriority, fTimeout, nil, nil);
  109.     VASSERT(fError == noErr, ("Problems with AESend = %d", fError));
  110.  
  111.     return fError;
  112. }
  113.  
  114.  
  115. #pragma segment AppleEvent
  116. void TAppleEvent::SetAddress(const AEAddressDesc address)
  117. // Set the address of the target AE.
  118. {
  119.     fError = ::AEPutAttributeDesc(&fAE, keyAddressAttr, &address);
  120.     VASSERT(fError == noErr, ("Problems with AEPutAttributeDesc = %d", fError));
  121. }
  122.  
  123.  
  124. //    GET/SET MEMBER FUNCTIONS
  125. #pragma segment AppleEvent
  126. long TAppleEvent::GetTimeoutValue() const
  127. // Get current timeout value.
  128. {
  129.     return fTimeout;
  130. }
  131.  
  132.  
  133. #pragma segment AppleEvent
  134. void TAppleEvent::SetTimeoutValue(const long value)
  135. // Set new timeout value.
  136. {
  137.     fTimeout = value;
  138. }
  139.  
  140.  
  141. #pragma segment AppleEvent
  142. AESendMode TAppleEvent::GetSendingMode() const
  143. // Get AE sending mode.
  144. {
  145.     return fSendMode;
  146. }
  147.  
  148.  
  149. #pragma segment AppleEvent
  150. void TAppleEvent::SetSendingMode(const AESendMode mode)
  151. // Set new AE sending mode.
  152. {
  153.     fSendMode = mode;
  154. }
  155.  
  156.  
  157. #pragma segment AppleEvent
  158. AESendPriority TAppleEvent::GetPriority() const
  159. // Get current priority level.
  160. {
  161.     return fPriority;
  162. }
  163.  
  164.  
  165. #pragma segment AppleEvent
  166. void TAppleEvent::SetPriority(const AESendPriority value)
  167. // Set new priority level.
  168. {
  169.     fPriority = value;
  170. }
  171.  
  172.  
  173. // _________________________________________________________________________________________________________ //
  174.  
  175. /*    Change History (most recent last):
  176.   No        Init.    Date        Comment
  177.   1            khs        11/22/92    New file
  178.   2            khs        1/7/93        Cleanup
  179. */
  180.  
  181.